package com.ehotting.edsta.circuitDesign.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.ehotting.edsta.circuitDesign.domain.EsCircuitType;
import com.ehotting.edsta.circuitDesign.service.IEsCircuitTypeService;
import com.ehotting.eaf.core.utils.poi.ExcelUtil;
import com.ehotting.eaf.core.web.controller.BaseController;
import com.ehotting.eaf.core.web.domain.AjaxResult;
import com.ehotting.eaf.core.web.page.TableDataInfo;
import com.ehotting.edsta.common.log.annotation.Log;
import com.ehotting.edsta.common.log.enums.BusinessType;
import com.ehotting.eaf.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 电路类型Controller
 * 
 * @author edsta
 * @date 2023-07-24
 */
@RestController
@RequestMapping("/circuitType")
public class EsCircuitTypeController extends BaseController
{
    @Autowired
    private IEsCircuitTypeService esCircuitTypeService;

    /**
     * 查询电路类型列表
     */
    //@PreAuthorize(hasPermi = "expert:circuitType:list")
    @GetMapping("/list")
    public TableDataInfo list(EsCircuitType esCircuitType)
    {
        startPage();
        List<EsCircuitType> list = esCircuitTypeService.selectEsCircuitTypeList(esCircuitType);
        return getDataTable(list);
    }

    /**
     * 查询电路类型列表
     */
    //@PreAuthorize(hasPermi = "expert:circuitType:allList")
    @GetMapping("/allList")
    public AjaxResult allList(EsCircuitType esCircuitType)
    {
        List<EsCircuitType> list = esCircuitTypeService.selectEsCircuitTypeList(esCircuitType);
        return AjaxResult.success(list);
    }

    /**
     * 导出电路类型列表
     */
    //@PreAuthorize(hasPermi = "expert:circuitType:export")
    @Log(title = "电路类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EsCircuitType esCircuitType) throws IOException
    {
        List<EsCircuitType> list = esCircuitTypeService.selectEsCircuitTypeList(esCircuitType);
        ExcelUtil<EsCircuitType> util = new ExcelUtil<EsCircuitType>(EsCircuitType.class);
        util.exportExcel(response, list, "电路类型数据");
    }

    /**
     * 获取电路类型详细信息
     */
    //@PreAuthorize(hasPermi = "expert:circuitType:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(esCircuitTypeService.selectEsCircuitTypeById(id));
    }

    /**
     * 新增电路类型
     */
    //@PreAuthorize(hasPermi = "expert:circuitType:add")
    @Log(title = "电路类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EsCircuitType esCircuitType)
    {
        return toAjax(esCircuitTypeService.insertEsCircuitType(esCircuitType));
    }

    /**
     * 修改电路类型
     */
    //@PreAuthorize(hasPermi = "expert:circuitType:edit")
    @Log(title = "电路类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EsCircuitType esCircuitType)
    {
        return toAjax(esCircuitTypeService.updateEsCircuitType(esCircuitType));
    }

    /**
     * 删除电路类型
     */
    //@PreAuthorize(hasPermi = "expert:circuitType:remove")
    @Log(title = "电路类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(esCircuitTypeService.deleteEsCircuitTypeByIds(ids));
    }

    @PostMapping("/test")
    public AjaxResult test(@RequestBody String value, HttpServletRequest request)
    {

        // 执行测试
        logger.info("value:{}", value);

        JSONObject jsonObject = JSONObject.parseObject(value);
        String input = jsonObject.getString("value");

        logger.info("input:{}", input);

        String data = "";
        return AjaxResult.success("", data);
    }

}
